<template>
  <el-button
    type="primary"
    plain
    size="mini"
    style="margin-bottom: 5px"
    :disabled="item.disabled||false"
    @click="handleClick"
  >{{ item.name }}
  </el-button>
</template>

<script>

import base from '../mixin/base'

export default {
  name: 'HeyTableElButtonDetail',
  components: {},
  mixins: [base],
  data() {
    return {}
  },
  computed: {},
  created() {
    const operateParam__ = {
      isValid: false
    }
    this.setParam({ ...this.operateParam_, ...operateParam__, ...this.operateParam, ...this.item.operateParam }, true)
  },
  mounted() {

  },
  methods: {
    genParam2() {
      const { selected, item, operateParam_, idField } = this
      const { param = {}, reqRow } = operateParam_
      const urlParam = {}
      urlParam.pageType = item.type
      const selectedValue = selected[0] || {}
      Object.keys(param).forEach(key => {
        const paramValue = param[key]
        if (paramValue && !key.includes('grp')) {
          urlParam[key] = paramValue
          return true
        }
        if (!key.includes('grp') && selectedValue.hasOwnProperty(key)) {
          urlParam[key] = selectedValue[key]
        }
      })
      const idValue = selectedValue[idField]
      if (idValue) {
        urlParam[idField] = idValue
      }
      if (reqRow) {
        Object.assign(urlParam, selectedValue)
      }
      return urlParam
    },
    canOpen() {
      if (this.selected.length !== 1) {
        this.$message.warning('仅支持单选操作')
        return false
      }
      return true
    },
    operate() {
      if (!this.canOpen() || !this.validate()) {
        return
      }
      this.openPage()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
